package com.example.hospitalmanagement.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import com.example.hospitalmanagement.R
import com.example.hospitalmanagement.bean.Data
import com.example.hospitalmanagement.bean.DeskWork
import com.example.hospitalmanagement.bean.SecondaryLinkageItem

/**
 * 预约挂号中右边列表适配器
 */
class DepartmentRightRecyclerViewAdapter(context: Context) :
    RecyclerView.Adapter<DepartmentRightRecyclerViewAdapter.RightHolder>() {
    private val context = context
    lateinit var dataList: MutableList<DeskWork>
    private lateinit var listener: (position: Int) -> Unit
    fun setListener(listener: (position: Int) -> Unit) {
        this.listener = listener
    }

    class RightHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val rightIcon: ImageView = itemView.findViewById(R.id.department_right_icon)
        val rightName: TextView = itemView.findViewById(R.id.department_right_text)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RightHolder {
        val rightHolder = RightHolder(
            LayoutInflater.from(context).inflate(R.layout.department_items_right, parent, false)
        )
        rightHolder.itemView.setOnClickListener {
            listener(rightHolder.adapterPosition)
        }
        return rightHolder
    }

    override fun onBindViewHolder(holder: RightHolder, position: Int) {
        if (dataList[position].checked) {
            holder.rightIcon.isVisible = true
            holder.rightName.setTextColor(context.getColor(R.color.dialog_button_color_unchecked))
        } else {
            holder.rightIcon.isGone = true
            holder.rightName.setTextColor(context.getColor(R.color.text_color))
        }
        holder.rightName.text = dataList[position].deskName
    }

    override fun getItemCount(): Int {
        return dataList.size
    }
}